<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('数据源列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            表名：<input type="text" name="tableName"/>
                            <input type="hidden" name="datasourceId"/>
                        </li>
						<li>
                            注解：<input type="text" name="tableComment"/>
						</li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="tableGen()" >
                <i class="fa fa-bug"></i> 生成代码
            </a>
            <a class="btn btn-success" onclick="viewWord()" >
                <i class="fa fa-street-view"></i> 预览
            </a>
            <a class="btn btn-success" onclick="downloadWord()" >
                <i class="fa fa-download"></i> 下载WORD
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('tool:datasource:edit')}]];
    var removeFlag = [[${@permission.hasPermi('tool:datasource:remove')}]];
    var prefix = ctx + "tool/datasource";
    var datasourceId = GetQueryString("datasourceId");
    var tablePrefix=GetQueryString("tablePrefix");
    $(function () {
        var options = {
            url: prefix + "/tableList?datasourceId="+datasourceId+'&tablePrefix='+tablePrefix,
            modalName: "数据库表",
            showExport: true,
            columns: [{
                checkbox: true
            },
                {
                    field: 'tableName',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'tableName',
                    title: '表名',
                    sortable: true
                },
                {
                    field: 'tableComment',
                    title: '数据源名称',
                    sortable: true
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    sortable: true
                }]
        };
        $.table.init(options);
    });

    // 删除信息
    function tableGen() {
        var rows = $.common.isEmpty($.table._option.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.uniqueId);
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        $.modal.open("生成代码", prefix+'/tableGen?tables='+rows.join()+'&datasourceId='+datasourceId);

    }
    // 删除信息
    function viewWord() {
        var rows = $.common.isEmpty($.table._option.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.uniqueId);
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        createMenuItem(prefix+'/viewDoc?tables='+rows.join()+'&datasourceId='+datasourceId,"预览");
    }
    // 删除信息
    function downloadWord() {
        var rows = $.common.isEmpty($.table._option.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.uniqueId);
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
       window.location.href=prefix+'/downloadWord?tables='+rows.join()+'&datasourceId='+datasourceId;

    }
</script>
</body>
</html>